﻿using System;
using System.Collections.Generic;
using System.Globalization;

namespace Gmantis.Controls.Chart
{
    internal class Keywords
    {
        // Fields
        private Dictionary<string, object> _words = new Dictionary<string, object>();

        // Methods
        internal string Replace(string s)
        {
            string format = s;
            int index = 0;
            foreach (string str2 in this._words.Keys)
            {
                if (format.IndexOf(str2, StringComparison.Ordinal) != -1)
                {
                    index++;
                }
            }
            if (index > 0)
            {
                object[] args = new object[index];
                index = 0;
                foreach (string str3 in this._words.Keys)
                {
                    if (format.IndexOf(str3, StringComparison.Ordinal) != -1)
                    {
                        args[index] = this._words[str3];
                        format = format.Replace(str3, index.ToString(CultureInfo.CurrentCulture));
                        index++;
                    }
                }
                try
                {
                    format = string.Format(CultureInfo.CurrentCulture, format, args);
                }
                catch
                {
                    throw new FormatException(Localizer.GetString("Bad format of keyword(s)") + ": " + s);
                }
            }
            return format;
        }

        // Properties
        internal object this[string name]
        {
            get
            {
                return this._words[name];
            }
            set
            {
                this._words[name] = value;
            }
        }
    }
}
